import instacne from "../request";

import type { Ref } from "vue";

// 登录返回数据

interface IAdminLoginParams {
    username: string;
    password: string;
}
interface IAdminLoginRes {
    tokenHead: string;
    token: string;
}
const adminlogin = (data: IAdminLoginParams): Promise<IAdminLoginRes> => {
    // instacne.post("/auth/login", data); 是一个 Promise 类型
    return instacne.post("/admin/login", data);
}

// 获取当前登录用户信息

interface IAdminInfoRes {
    menus: IMneuItem[];
    username: string;
    roles: string[];
}
const getAdminInfo = (): Promise<IAdminInfoRes> => {
    return instacne.get('/admin/info')
}

// 根据用户名或者姓名获取的分页的用户列表
interface IAdminListParams {
    keyword?: string | Ref<string>;
    pageNum?: number | Ref<number>;
    pageSize?: number | Ref<number>;
}

interface IAdminListItem {
    createTime: string;
    email: string;
    icon: string;
    id: number;
    loginTime: string;
    nickName: string;
    note: string;
    password: string;
    status: number;
    username: string;
    total:number;
}

interface IAdminListRes {
    list: IAdminListItem[];
    pageNum: number;
    pageSize: number;
    total: number;
    totalPage: number;
}


const getAdminList = (data: IAdminListParams): Promise<IAdminListRes> => {
    return instacne.get('admin/list', {
        params: data,
    })
}

interface IRoleListItem {
    adminCount: number
    createTime: string;
    description: string;
    id: number;
    name: string;
    sort: number;
    status: number;
}
interface IRoleListRes {
    list: IRoleListItem[];
    pageNum: number;
    pageSize: number;
    total: number;
    totalPage: number;
}
// role/list 根据角色名称分页获取角色列表
const getRoleList = (data: IAdminListParams): Promise<IRoleListRes> => {
    return instacne.get('role/list', {
        params: data,
    })
}
/**
 * 新增用户
 * admin/register
 */
const adminRegister = (data: IAdminListItem): Promise<IAdminListItem> => {
    return instacne.post("/admin/register", data);
  };
 const adminUpdate = (data : IAdminListItem) => {
    return instacne.post(`/admin/update/${data.id}`,data)
  }
// 权限下的菜单列表 /mall-admin/menu/list/0?pageNum=1&pageSize=10
const OnMenu = (data:IAdminListParams): Promise<IRoleListRes> =>{ 
    return instacne.get('/menu/list/0',{
        params: data,
    })
}
// 获取index首页的 图表数据接口
const GetIndexDataApi = () :Promise<any> => {
    return instacne.get('http://kumanxuan1.f3322.net:8360/admin/stat')
  } 
export { adminlogin, getAdminInfo, getAdminList, getRoleList, adminRegister, adminUpdate, OnMenu, GetIndexDataApi };
export type { IAdminLoginParams, IAdminLoginRes, IAdminListItem };




